package com.lingtu.shopwxserver.utils;

import com.lingtu.shopwxserver.pojo.TextMessage;
import com.thoughtworks.xstream.XStream;

/**
 * @ClassName TextMessageUtil
 * @Description 文本消息工具类
 * @Author MaShuai
 * @Date 2018/11/22 12:26
 * @Version 1.0
 **/
public class TextMessageUtil implements BaseMessageUtil<TextMessage>{

    /**
     * @Description 将发送消息封装成对应的xml格式
     * @Param [message]
     * @return java.lang.String
     */
    @Override
    public String messageToXml(TextMessage message) {
        XStream xstream  = new XStream();
        xstream.alias("xml", message.getClass());
        return xstream.toXML(message);
    }

    /**
     * @Description 封装发送消息对象,封装时，需要将调换发送者和接收者的关系
     * @Param [FromUserName, ToUserName]
     * @return java.lang.String
     */
    @Override
    public String initMessage(String fromUserName, String toUserName) {
        TextMessage text = new TextMessage();
        text.setToUserName(fromUserName);
        text.setFromUserName(toUserName);
        text.setContent("欢迎关注灵图商城,现在只有商城图片和美女图片，请输入‘商城’或‘美女’进行选择！");
        text.setCreateTime(System.currentTimeMillis());
        text.setMsgType("text");
        return  messageToXml(text);
    }





}
